const mongoose = require('mongoose');

const ProjectVersionSchema = new mongoose.Schema({
  projectId: { type: mongoose.Schema.Types.ObjectId, ref: 'Project', required: true, index: true },
  versionTag: { type: String, required: true },
  description: { type: String, default: '' },
  publishedAt: { type: Date, default: Date.now },
  publishedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
  snapshot: { type: Object, required: true },
  snapshotHash: { type: String }
}, { timestamps: true });

ProjectVersionSchema.index({ projectId: 1, versionTag: 1 }, { unique: true });

module.exports = mongoose.model('ProjectVersion', ProjectVersionSchema);


